Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
74 / 74
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
ServiceProvider
100.00% covered (success)
100.00%
74 / 74
100.00% covered (success)
100.00%
6 / 6
36
100.00% covered (success)
100.00%
1 / 1
 boot
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
3
 about
100.00% covered (success)
100.00%
29 / 29
100.00% covered (success)
100.00%
1 / 1
23
 userPrimaryKeyType
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
4
 userPrimaryKeyTypeParse
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
1 / 1
4
 register
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 version
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4/**
5 * Playground
6 */
7namespace Playground;
8
9use Illuminate\Foundation\Console\AboutCommand;
10use Illuminate\Foundation\Support\Providers\AuthServiceProvider;
11
12/**
13 * \Playground\ServiceProvider
14 */
15class ServiceProvider extends AuthServiceProvider
16{
17    protected string $package = 'playground';
18
19    public const VERSION = '73.0.0';
20
21    public function boot(): void
22    {
23        /**
24         * @var array<string, mixed> $config
25         */
26        $config = config($this->package);
27
28        if ($this->app->runningInConsole()) {
29            // Publish configuration
30            $this->publishes([
31                sprintf('%1$s/config/%2$s.php', dirname(__DIR__), $this->package) => config_path(sprintf('%1$s.php', $this->package)),
32            ], 'playground-config');
33        }
34
35        if (! empty($config['about'])) {
36            $this->about($config);
37        }
38    }
39
40    /**
41     * @param array<string, mixed> $config
42     */
43    public function about(array $config): void
44    {
45        $packages = ! empty($config['packages']) && is_array($config['packages']) ? $config['packages'] : [];
46
47        $version = $this->version();
48
49        /**
50         * @var class-string $auth_providers_users_model
51         */
52        $auth_providers_users_model = config('auth.providers.users.model');
53
54        AboutCommand::add('Playground', fn () => [
55            '<fg=cyan;options=bold>User</> [auth.providers.users.model]' => sprintf('[%s]', is_string($auth_providers_users_model) ? $auth_providers_users_model : ''),
56            '<fg=cyan;options=bold>User Primary</>' => $this->userPrimaryKeyType($auth_providers_users_model),
57
58            '<fg=cyan;options=bold>User</> Illuminate\Database\Eloquent\Factories\HasFactory' => $this->userHasFactory ? '<fg=green;options=bold>USED</>' : '<fg=yellow;options=bold>NOT USED</>',
59            '<fg=cyan;options=bold>User</> Illuminate\Database\Eloquent\Model' => $this->userIsEloquentModel ? '<fg=green;options=bold>EXTENDED</>' : '<fg=yellow;options=bold>NOT EXTENDED</>',
60            '<fg=cyan;options=bold>User</> Illuminate\Database\Eloquent\Concerns\HasUuids' => $this->userHasEloquentUuids ? '<fg=green;options=bold>USED</>' : '<fg=yellow;options=bold>NOT USED</>',
61            '<fg=cyan;options=bold>User</> Illuminate\Notifications\Notifiable' => $this->userHasNotifiable ? '<fg=green;options=bold>USED</>' : '<fg=yellow;options=bold>NOT USED</>',
62            '<fg=cyan;options=bold>User</> Illuminate\Contracts\Auth\MustVerifyEmail' => $this->userHasMustVerifyEmail ? '<fg=green;options=bold>IMPLEMENTED</>' : '<fg=yellow;options=bold>NOT IMPLEMENTED</>',
63
64            '<fg=cyan;options=bold>User</> Illuminate\Auth\Passwords\CanResetPassword' => $this->userCanResetPasswordConcern ? '<fg=green;options=bold>USED</>' : '<fg=yellow;options=bold>NOT USED</>',
65            '<fg=cyan;options=bold>User</> Illuminate\Contracts\Auth\CanResetPassword' => $this->userCanResetPasswordContract ? '<fg=green;options=bold>IMPLEMENTED</>' : '<fg=yellow;options=bold>NOT IMPLEMENTED</>',
66
67            '<fg=cyan;options=bold>User</> Illuminate\Foundation\Auth\Access\Authorizable' => $this->userHasAuthorizableConcerns ? '<fg=green;options=bold>USED</>' : '<fg=yellow;options=bold>NOT USED</>',
68            '<fg=cyan;options=bold>User</> Illuminate\Contracts\Auth\Access\Authorizable' => $this->userHasAuthorizableContracts ? '<fg=green;options=bold>IMPLEMENTED</>' : '<fg=yellow;options=bold>NOT IMPLEMENTED</>',
69
70            '<fg=cyan;options=bold>User</> Illuminate\Auth\Authenticatable' => $this->userHasAuthenticatableConcerns ? '<fg=green;options=bold>USED</>' : '<fg=yellow;options=bold>NOT USED</>',
71            '<fg=cyan;options=bold>User</> Illuminate\Contracts\Auth\Authenticatable' => $this->userHasAuthenticatableContracts ? '<fg=green;options=bold>IMPLEMENTED</>' : '<fg=yellow;options=bold>NOT IMPLEMENTED</>',
72
73            '<fg=cyan;options=bold>User</> Playground\Models\Concerns\Abilities' => $this->userPlaygroundAbilitiesConcerns ? '<fg=green;options=bold>USED</>' : '<fg=yellow;options=bold>NOT USED</>',
74            '<fg=cyan;options=bold>User</> Playground\Models\Contracts\Abilities' => $this->userHasPlaygroundAbilitiesContracts ? '<fg=green;options=bold>IMPLEMENTED</>' : '<fg=yellow;options=bold>NOT IMPLEMENTED</>',
75
76            '<fg=cyan;options=bold>User</> Playground\Models\Concerns\Admin' => $this->userPlaygroundAdminConcerns ? '<fg=green;options=bold>USED</>' : '<fg=yellow;options=bold>NOT USED</>',
77            '<fg=cyan;options=bold>User</> Playground\Models\Contracts\Admin' => $this->userHasPlaygroundAdminContracts ? '<fg=green;options=bold>IMPLEMENTED</>' : '<fg=yellow;options=bold>NOT IMPLEMENTED</>',
78
79            '<fg=cyan;options=bold>User</> Playground\Models\Concerns\Privileges' => $this->userPlaygroundPrivilegesConcerns ? '<fg=green;options=bold>USED</>' : '<fg=yellow;options=bold>NOT USED</>',
80            '<fg=cyan;options=bold>User</> Playground\Models\Contracts\Privileges' => $this->userHasPlaygroundPrivilegesContracts ? '<fg=green;options=bold>IMPLEMENTED</>' : '<fg=yellow;options=bold>NOT IMPLEMENTED</>',
81
82            '<fg=cyan;options=bold>User</> Playground\Models\Concerns\Role' => $this->userPlaygroundRoleConcerns ? '<fg=green;options=bold>USED</>' : '<fg=yellow;options=bold>NOT USED</>',
83            '<fg=cyan;options=bold>User</> Playground\Models\Contracts\Role' => $this->userHasPlaygroundRoleContracts ? '<fg=green;options=bold>IMPLEMENTED</>' : '<fg=yellow;options=bold>NOT IMPLEMENTED</>',
84
85            'Packages' => implode(', ', $packages),
86            'Package' => $this->package,
87            'Version' => $version,
88        ]);
89    }
90
91    /**
92     * @param ?class-string $auth_providers_users_model
93     */
94    public function userPrimaryKeyType(string $auth_providers_users_model = null): string
95    {
96        try {
97            if (! $auth_providers_users_model || ! class_exists($auth_providers_users_model)) {
98                return '<fg=yellow;options=bold>invalid</>';
99            }
100
101            return $this->userPrimaryKeyTypeParse($auth_providers_users_model);
102        } catch (\Throwable $th) {
103            \Log::debug($th->__toString());
104
105            return '<fg=red;options=bold>error</>';
106        }
107    }
108
109    protected bool $userHasFactory;
110
111    protected bool $userCanResetPasswordConcern;
112
113    protected bool $userCanResetPasswordContract;
114
115    protected bool $userHasAuthorizableConcerns;
116
117    protected bool $userHasAuthorizableContracts;
118
119    protected bool $userIsEloquentModel;
120
121    protected bool $userHasEloquentUuids;
122
123    protected bool $userHasNotifiable;
124
125    protected bool $userHasAuthenticatableConcerns;
126
127    protected bool $userHasAuthenticatableContracts;
128
129    protected bool $userHasMustVerifyEmail;
130
131    protected bool $userPlaygroundAbilitiesConcerns;
132
133    protected bool $userHasPlaygroundAbilitiesContracts;
134
135    protected bool $userPlaygroundAdminConcerns;
136
137    protected bool $userHasPlaygroundAdminContracts;
138
139    protected bool $userPlaygroundPrivilegesConcerns;
140
141    protected bool $userHasPlaygroundPrivilegesContracts;
142
143    protected bool $userPlaygroundRoleConcerns;
144
145    protected bool $userHasPlaygroundRoleContracts;
146
147    /**
148     * @param class-string $auth_providers_users_model
149     */
150    private function userPrimaryKeyTypeParse(string $auth_providers_users_model): string
151    {
152        $model_info = '';
153        /**
154         * @var \Illuminate\Contracts\Auth\Authenticatable
155         */
156        $user = new $auth_providers_users_model;
157
158        $this->userHasFactory = in_array(\Illuminate\Database\Eloquent\Factories\HasFactory::class, class_uses_recursive($user));
159
160        $this->userCanResetPasswordConcern = in_array(\Illuminate\Auth\Passwords\CanResetPassword::class, class_uses_recursive($user));
161        $this->userCanResetPasswordContract = $user instanceof \Illuminate\Contracts\Auth\CanResetPassword;
162
163        $this->userHasAuthorizableConcerns = in_array(\Illuminate\Foundation\Auth\Access\Authorizable::class, class_uses_recursive($user));
164        $this->userHasAuthorizableContracts = $user instanceof \Illuminate\Contracts\Auth\Access\Authorizable;
165
166        $this->userIsEloquentModel = $user instanceof \Illuminate\Database\Eloquent\Model;
167
168        $this->userHasEloquentUuids = in_array(\Illuminate\Database\Eloquent\Concerns\HasUuids::class, class_uses_recursive($user));
169        $this->userHasNotifiable = in_array(\Illuminate\Notifications\Notifiable::class, class_uses_recursive($user));
170
171        $this->userHasAuthenticatableConcerns = in_array(\Illuminate\Auth\Authenticatable::class, class_uses_recursive($user));
172        $this->userHasAuthenticatableContracts = $user instanceof \Illuminate\Contracts\Auth\Authenticatable;
173
174        $this->userHasMustVerifyEmail = $user instanceof \Illuminate\Contracts\Auth\MustVerifyEmail;
175
176        $this->userPlaygroundAbilitiesConcerns = in_array(Models\Concerns\Abilities::class, class_uses_recursive($user));
177        $this->userHasPlaygroundAbilitiesContracts = $user instanceof Models\Contracts\Abilities;
178
179        $this->userPlaygroundAdminConcerns = in_array(Models\Concerns\Admin::class, class_uses_recursive($user));
180        $this->userHasPlaygroundAdminContracts = $user instanceof Models\Contracts\Admin;
181
182        $this->userPlaygroundPrivilegesConcerns = in_array(Models\Concerns\Privileges::class, class_uses_recursive($user));
183        $this->userHasPlaygroundPrivilegesContracts = $user instanceof Models\Contracts\Privileges;
184
185        $this->userPlaygroundRoleConcerns = in_array(Models\Concerns\Role::class, class_uses_recursive($user));
186        $this->userHasPlaygroundRoleContracts = $user instanceof Models\Contracts\Role;
187
188        if (in_array(\Illuminate\Database\Eloquent\Concerns\HasUuids::class, class_uses_recursive($user))
189            && ! $user->getIncrementing()
190        ) {
191            $model_info = '<fg=green;options=bold>UUID</>';
192        } elseif ($user->getIncrementing()) {
193            $model_info = '<fg=green;options=bold>increments</>';
194        }
195
196        return $model_info;
197    }
198
199    public function register(): void
200    {
201        $this->mergeConfigFrom(
202            sprintf('%1$s/config/%2$s.php', dirname(__DIR__), $this->package),
203            $this->package
204        );
205    }
206
207    public function version(): string
208    {
209        return static::VERSION;
210    }
211}